<form id="queryForm" class="hide">
    <div class="row" style="margin: 1em">
        <div class="col-sm-2"><input type="text" id="date" name="end" class="form-control" placeholder="提现申请截止日期"></div>
        <div class="col-sm-1"><input type="text" id="agent" name="agent"  class="form-control" placeholder="代理编号"></div>
        <div class="col-sm-1"><input type="button" id="search" class="btn btn-primary" value="查询"></div>
    </div>
</form>




<div class="box">
    <div class="box-header">
        <div class="box-name">
            <i class="fa fa-table"></i>
            <span>代理提成</span>
        </div>
        <div class="box-icons">
            <a class="collapse-link">
                <i class="fa fa-chevron-up"></i>
            </a>
            <a class="expand-link">
                <i class="fa fa-expand"></i>
            </a>
            <a class="close-link">
                <i class="fa fa-times"></i>
            </a>
        </div>
        <div class="no-move"></div>
    </div>
    <div class="box-content no-padding">
        <table class="table table-striped table-bordered table-hover table-heading no-border-bottom">
            <thead>
            <tr>
                <th>用户ID</th>
                <th>代理姓名</th>
                <th>代理昵称</th>
                <th>提取账号</th>
                <th>下级代理返利</th>
                <th>绑定用户返利</th>
                <th>总充值金额</th>
                <th>总返利金额</th>
                <th>未提现金额</th>
                <th>累计提现金额</th>
                <th>未结算金额</th>
                <th>已结算金额</th>
                <th>结算</th>
                <th>提现明细</th>
            </tr>
            </thead>
            <tbody>
            <{include file="AgentBenefit_data.html"}>
            </tbody>
        </table>
    </div>
</div>

<script src="/Public/My97DatePicker/WdatePicker.js"></script>
<script>
    var doing=false;
    $('.pay').click(pay);
    $('.detail').click(detail);
    $('#search').click(function(){
        var data=$('#queryForm').serialize();
        $.post("<{U('Game/getAgentBenefit')}>",data,function(re){
            $('#content').html(re);
            $('.pay').click(pay);
            $('.detail').click(detail);
        },'HTML');
    });

    function pay(){

        var obj=$(this).prev();
        var agentID=obj.attr('agentId');
        var agent=obj.attr('agent');
        var money=obj.val();
        if(money+0<1){
            alert("结算金额未输入");
            return false;
        }

        var tips="确定结算吗？\n 代理:"+agent+" \r 编号:"+agentID+" \r 金额:"+money;
        if(!window.confirm(tips)){
            return false;
        }
        if(doing){
            alert("已有操作在处理，请勿重复提交");
            return;
        }

        doing=true;
        $.post("<{U('Game/agentPayDo')}>",{agentID:agentID,money:money},function(re){
            doing=false;
            if(re.status!=0){
                alert(re.msg);
                return;
            }else{
                var unpay=$('#unpay_'+re.id);
                var pay=$('#pay_'+re.id);
                unpay.text(parseFloat(unpay.text()) - re.money);
                pay.text(parseFloat(pay.text()) + re.money);
                if(parseFloat(unpay.text())<=0){
                    pay.next().empty();
                }else{}
                pay.next().find('input').val(0);
            }

        },'JSON');

    }
    function detail(){
        var agentID=$(this).attr('agentId');
        layer.open({
            type: 2,
            area: ['900px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: "<{U('Game/agentExtractLog')}>&agentId="+agentID
        });
    }
    $("#date").focus(function(){
        WdatePicker({
            dateFmt:'yyyy-MM-dd'
        })
    });

</script>
